function add0(m){return m<10?'0'+m:m }
function format(shijianchuo)
{
//shijianchuo是整数，否则要parseInt转换
var time = new Date(shijianchuo);
var y = time.getFullYear();
var m = time.getMonth()+1;
var d = time.getDate();
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
}
$(document).ready(function(){
	
	var testdriveAppointmentId = getQueryParamValue("testdriveAppointmentId");
	
	var rootPath = getRootPath();
	
	
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/testdrivingAppointment/selectTestDrive/id?testdriveAppointmentId='+testdriveAppointmentId,
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){
			
			var wholeHtml = '';
			
			$.each(resultData,function(testdrivingIndex,testdrivingObj){
				
				var testdrivingHtml = '';

				var appointmentStatus = '';
				
				if(testdrivingObj.appointmentStatus==10011001){
					appointmentStatus = '受理中';
					
					testdrivingHtml = testdrivingHtml + '<div class="panel panel-default">'
													  +   '<ul class="list-group">'
													  +     '<li class="list-group-item">试驾车型：'+testdrivingObj.packageCodeName+'</li>'
													  +		'<li class="list-group-item">'
													  +		  '<span>联系人：'+testdrivingObj.personalName+'</span><br><br>'
													  +		  '<span>手机号码：'+testdrivingObj.phone+'</span><br><br>'
													  +		  '<span>预约时间：'+format(testdrivingObj.createDate)+'</span><br><br>'
													  +		  '<span>试驾时间：'+testdrivingObj.startDate+'</span><br><br>'
													  +		 '</li>'
													  +    '</ul>'
													  + '</div>'
													  + '<div class="panel panel-default">'
													  +   '<ul class="list-group">'
													  +     '<li class="list-group-item">'
													  +		  '预约状态：<span style="color:red">'+appointmentStatus+'</span><br><br>'
													  +		  '<span>我们将以最快速度为您安排，请稍作等候。</span><br><br>'
													  +		  '<span>销售顾问：'+testdrivingObj.saName+'</span><br><br>'
													  +		'</li>'
													  +    '</ul>'
													  + '</div>'
													  + '<div class="panel panel-default">'
													  +   '<input style="background-color:gray" type="button" data-toggle="modal" data-target="#myModal"  value="取消预约" class="btn btn-default btn-lg btn-block" />'
													  + '</div>'
				}
				else if(testdrivingObj.appointmentStatus==10011002){
					appointmentStatus = '已到店';
					
					testdrivingHtml = testdrivingHtml + '<div class="panel panel-default">'
					  +   '<ul class="list-group">'
					  +     '<li class="list-group-item">试驾车型：'+testdrivingObj.packageCodeName+'</li>'
					  +		'<li class="list-group-item">'
					  +		  '<span>联系人：'+testdrivingObj.personalName+'</span><br><br>'
					  +		  '<span>手机号码：'+testdrivingObj.phone+'</span><br><br>'
					  +		  '<span>预约时间：'+format(testdrivingObj.createDate)+'</span><br><br>'
					  +		  '<span>试驾时间：'+testdrivingObj.startDate+'</span><br><br>'
					  +		 '</li>'
					  +    '</ul>'
					  + '</div>'
					  + '<div class="panel panel-default">'
					  +   '<ul class="list-group">'
					  +     '<li class="list-group-item">'
					  +		  '预约状态：<span style="color:blue">'+appointmentStatus+'</span><br><br>'
					  +		  '<span>您已完成试驾，感谢您的光临。</span><br><br>'
					  +		  '<span>销售顾问：'+testdrivingObj.saName+'</span><br><br>'
					  +		'</li>'
					  +    '</ul>'
					  + '</div>'
				}
				else if(testdrivingObj.appointmentStatus==10011003){
					appointmentStatus = '已取消';
					
					testdrivingHtml = testdrivingHtml + '<div class="panel panel-default">'
					  +   '<ul class="list-group">'
					  +     '<li class="list-group-item">试驾车型：'+testdrivingObj.packageCodeName+'</li>'
					  +		'<li class="list-group-item">'
					  +		  '<span>联系人：'+testdrivingObj.personalName+'</span><br><br>'
					  +		  '<span>手机号码：'+testdrivingObj.phone+'</span><br><br>'
					  +		  '<span>预约时间：'+format(testdrivingObj.createDate)+'</span><br><br>'
					  +		  '<span>试驾时间：'+testdrivingObj.startDate+'</span><br><br>'
					  +		 '</li>'
					  +    '</ul>'
					  + '</div>'
					  + '<div class="panel panel-default">'
					  +   '<ul class="list-group">'
					  +     '<li class="list-group-item">'
					  +		  '预约状态：<span style="color:gray">'+appointmentStatus+'</span><br><br>'
					  +		  '<span>您的试驾预约已取消。</span><br><br>'
					  +		  '<span>销售顾问：'+testdrivingObj.saName+'</span><br><br>'
					  +		'</li>'
					  +    '</ul>'
					  + '</div>'
				}
				else{ 
					appointmentStatus = '已确认';
					
					testdrivingHtml = testdrivingHtml + '<div class="panel panel-default">'
					  +   '<ul class="list-group">'
					  +     '<li class="list-group-item">试驾车型：'+testdrivingObj.packageCodeName+'</li>'
					  +		'<li class="list-group-item">'
					  +		  '<span>联系人：'+testdrivingObj.personalName+'</span><br><br>'
					  +		  '<span>手机号码：'+testdrivingObj.phone+'</span><br><br>'
					  +		  '<span>预约时间：'+format(testdrivingObj.createDate)+'</span><br><br>'
					  +		  '<span>试驾时间：'+testdrivingObj.startDate+'</span><br><br>'
					  +		 '</li>'
					  +    '</ul>'
					  + '</div>'
					  + '<div class="panel panel-default">'
					  +   '<ul class="list-group">'
					  +     '<li class="list-group-item">'
					  +		  '预约状态：<span style="color:red">'+appointmentStatus+'</span><br><br>'
					  +		  '<span>您的试驾预约已确认。</span><br><br>'
					  +		  '<span>销售顾问：'+testdrivingObj.saName+'</span><br><br>'
					  +		'</li>'
					  +    '</ul>'
					  + '</div>'
				}				  
				
				wholeHtml += testdrivingHtml;
			});
			
			$("#information").append(wholeHtml);
		}
	});
})
